package csc.fresher.finalgroupfour.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import csc.fresher.finalgroupfour.domain.Account;
import csc.fresher.finalgroupfour.domain.User;
import csc.fresher.finalgroupfour.service.AccountService;
import csc.fresher.finalgroupfour.service.UserService;


@Controller
public class AccountController {
	@Autowired
	private UserService userService;
	
	@Autowired
	private AccountService accountService;
	
	/**
	 * @return
	 * Render user's account view. 
	 */
	@RequestMapping(value="/viewAccount")
	public ModelAndView viewAccount() {
		ModelAndView model = new ModelAndView("viewAccount");
		String loginId = userService.getLoginId();
		User user = userService.findUser(loginId);
		//Show account's list depend on user's role
		List<Account> accountList = accountService.listAccounts(user);
		
		model.addObject("accountList", accountList);
		return model;
	}
}
